<!--计量单位选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="800px" @ok="handleOk" destroyOnClose @visible-change="visibleChange">
      <BasicTable
        :columns="columns"
        v-bind="config"
        :useSearchForm="true"
        :formConfig="formConfig"
        :api="psPreAlwaysSchedulingSchemeList"
        :searchInfo="searchInfo"
        :rowSelection="rowSelection"
        :indexColumnProps="indexColumnProps"
      ></BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { psPreAlwaysSchedulingSchemeList } from './base.api';
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
import { useSelectBiz } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
import { selectProps } from '/@/components/Form/src/jeecg/props/props';
import { useAttrs } from '/@/hooks/core/useAttrs';

export default defineComponent({
  name: 'CalculateSelectModal',
  components: {
    //此处需要异步加载BasicTable
    BasicModal,
    BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
      loading: true,
    }),
  },
  props: {
    ...selectProps,
    //选择框标题
    modalTitle: {
      type: String,
      default: '排产方案选择',
    },
  },

  emits: ['register', 'getSelectResult'],
  setup(props, { emit }) {
    //注册弹框
    const [register, { closeModal }] = useModalInner();
    const attrs = useAttrs();
    //表格配置
    const config = {
      canResize: false,
      bordered: true,
      size: 'small',
      rowKey: unref(props).rowKey,
      labelKey: 'schedulingSchemeName',
      isRadioSelection: true,
    };
    const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
    const [{ rowSelection, indexColumnProps, visibleChange, getSelectResult }] = useSelectBiz(psPreAlwaysSchedulingSchemeList, getBindValue);
    rowSelection.columnWidth = 50;
    indexColumnProps.width = 50;
    const searchInfo = ref(props.params);
    //查询form
    const formConfig = {
      labelWidth: 100,
      baseColProps: {
        xs: 8,
        sm: 8,
        md: 8,
        lg: 8,
      },
      schemas: [
        {
          label: '排产方案编码',
          field: 'schedulingSchemeCode',
          component: 'JInput',
          colProps: { span: 8 },
        },
        {
          label: '排产方案名称',
          field: 'schedulingSchemeName',
          component: 'JInput',
          colProps: { span: 8 },
        },
      ],
    };
    //   useModal((data: any) => {
    //     console.log(data);
    //   });
    //定义表格列
    const columns = [
  {
    title: '排产方案编码',
    align: "center",
    dataIndex: 'schedulingSchemeCode'
  },
  {
    title: '排产方案',
    align: "center",
    dataIndex: 'schedulingSchemeName'
  },
  //  {
  //   title: '时间格式id',
  //   align:"center",
  //   dataIndex: 'timeFormatId'
  //  },
  {
    title: '时格',
    align: "center",
    dataIndex: 'timeFormatName'
  },
  {
    title: '基础算法',
    align: "center",
    dataIndex: 'basicAlgorithm',
    customRender: ({ text }) => {
      return text == 1 ? "最短工期" : text == 2 ? '最早交货期' : text == 3 ? "按照交期与工期之间的距离" : text == 4 ? 'CR值' : ''
    },
  },
  {
    title: '结束时间',
    align: "center",
    dataIndex: 'endTime',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
  },
  {
    title: '是否已启用',
    align: "center",
    dataIndex: 'significantCondition',
    customRender: ({ text }) => {
      return text == 0 ? "否" : text == 1 ? '是' : ''
    },
  },
  {
    title: '第三方编码',
    align: "center",
    dataIndex: 'thirdPartyCode',
    ifShow: false
  },
  {
    title: '备注',
    align: "center",
    dataIndex: 'remark'
  },
    ];

    /**
     * 确定选择
     */
    function handleOk() {
      getSelectResult((options, values) => {
        //回传选项和已选择的值
        emit('getSelectResult', options, values);
        //关闭弹窗
        closeModal();
      });
    }

    return {
      config,
      handleOk,
      searchInfo,
      register,
      indexColumnProps,
      visibleChange,
      psPreAlwaysSchedulingSchemeList,
      formConfig,
      getBindValue,
      columns,
      rowSelection,
    };
  },
});
</script>
